package 快速排序;

public class quick3 {
    public static void main(String[] args) {
        /*1.定义静态数组*/
        int[] a = {23,12,24,54,7,3,43};
        //2.声明快速方法
        quickFast(a,0,a.length-1);//数组名+下标0+下标尾
        //3.遍历数组，打印结果
        for (int m:a
             ) {
            System.out.println(m);
        }

    }
     //2.1快速排序方法，无返回值
    private static void quickFast(int[] a, int low, int high) { //改第二/三个形参数
        if(low < high){ //2.2前提判断
            int index = getIndex(a,low,high);//2.3声明获取下标方法
            //2.4low和high的排序结果
            quickFast(a, low, index-1);
             quickFast(a, index+1, high);
        }
    }

    private static int getIndex(int[] a, int low, int high) {
        //
         int tmp = a[low];
         while (low<high ){
             while (low<high && a[high] >= tmp){
                 high--;
             }
             a[low]=a[high];
             while (low<high && a[high] <= tmp){
                 low++;
             }
             a[high] = a[low];

         }
           //循环外tmp赋值
          a[low]=tmp;
         return low; //返回low
    }

}
